Draws a filled, axis-aligned rectangle w wide and h tall, with its top-left corner at (x, y) - world space (the shared camera is attached, same as draw_sprite). So draw_rect_fill(x, y, 10, 4, c) covers x to x + 10 across and y to y + 4 down. Inside a Draw GUI event it is fixed to the screen instead, and (x, y) counts from the screen’s top-left pixel, so draw_rect_fill(0, 0, screen_width(), screen_height(), COLOR_BLUE) fills the whole screen. A real sprite, not paint: see the "On the GBA" note for exactly what that costs.
Works differently on Game Boy - A rectangle on the Game Boy is made of sprites and drawn in the 4 shades: red, blue and magenta come out dark grey, green, yellow, cyan and white light grey. It shares the 40 sprites on the screen (10 a line); a big box is cut short.
Works differently on Game Boy Color - Rectangles are made of sprites and share the 40 on the screen (10 a line): bars, frames and small boxes are exact, a big box is cut short. Colors come 3 to a free sprite palette, others become the nearest. On the screen they are behind sprites and text.
On other consoles this differs: see Side by side and How the consoles differ.
draw_rect_fill(x, y, w, h, color)| Name | Type |
|---|---|
x | real |
y | real |
w | real |
h | real |
color | shape_color |
Nothing.
Draws a filled, axis-aligned rectangle w pixels wide and h pixels tall, with its top-left corner at (x, y) - world space, scrolling with the camera the same way draw_sprite does. So draw_rect_fill(10, 20, 30, 5, COLOR_RED) covers x from 10 to 40 and y from 20 to 25.
The counting starts at the room's top-left corner, so (x, y) is a place in the room, counted from the room's top-left corner, and it is where the rectangle's own top-left corner goes.
A sprite is different: it goes by its own origin, a spot you pick for each sprite in the Paint tab. A rectangle has no origin to pick, so it always goes by its corner.
This is a real sprite, not paint: the Game Boy Advance has no per-pixel drawing surface to paint a rectangle into, so a filled rectangle here is made of the engine's own flat-colour sprites, stretched to size - see "Any size, exactly" below and "On the GBA" for what that costs, worth reading before scattering dozens of these across a room.
color is one of COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_CYAN, COLOR_MAGENTA.
In a Draw GUI event the same call is fixed to the screen instead. There (x, y) counts from the top-left pixel of the screen (the screen is 240 by 160), the rectangle never scrolls with the camera, and it is in front of the whole world. So draw_rect_fill(0, 0, screen_width(), screen_height(), COLOR_BLUE) in a Draw GUI event fills the whole screen. That is what a health-bar backing, a dialogue panel or a debug box pinned to a corner uses; in a Draw event the rectangle is a marker or an effect that belongs to a place in the room. To fix a rectangle to the screen from some other event, use draw_rect_fill_anchored.
There is no rotated form yet - see draw_rect for an unfilled outline instead of a filled rectangle.
w and h can be any size, and the rectangle is exactly that many pixels: 6 wide is 6 wide, and 200 wide is 200. (A size with a fraction is rounded to the nearest whole pixel, and a size of 0 or less is 1.)
The console can only stretch one sprite to about twice its own size, so a big rectangle is built from several sprites laid side by side with no gaps - you cannot see where one stops and the next starts. The engine does the cutting. About how many sprites a rectangle takes:
| The rectangle | Sprites |
|---|---|
| 8 by 8, and most sizes up to 16 by 16 (each way an odd number, or 2, 4, 8 or 16) | 1 |
| 6 by 6, 12 by 12, 20 by 10 (an even number that is not 2, 4, 8 or 16 needs two pieces each way) | 4 |
| a 200 by 16 bar | 7 |
| the whole 240 by 160 screen | 12 |
A rectangle whose sides are each at least 8 is cut, when that is cheaper for the console, into pieces that are exactly a sprite's own size (8, 16, 32 or 64 pixels on a side), laid over each other where they have to be - the color is flat, so you cannot see it. That is why a bar or a panel takes a few more sprites than a stretched cut would, and why those pieces need no matrix. Every other rectangle uses one of the 32 matrices (and none if it is exactly 8 by 8), for as long as the call keeps being made. Every rectangle in the game shares one palette bank, whatever its color - one of the console's 16 sprite palettes. To spend none, draw in a color of a palette your sprites already wear: palette_color.
Two limits. One rectangle is at most 12 sprites, which is about 380 pixels wide by 500 tall at the very most (a 300 by 20 bar is 10): ask for more and it is drawn smaller than you asked, around the same middle, and a development build writes a line in mGBA's log saying so. For a whole floor or a wall, paint a tile layer instead. And the console has a fixed amount of time to draw each row of the screen (1,210 cycles) and a stretched sprite costs about 10 plus twice the width of its box: a box 16 pixels wide costs about 42, so only about 28 of those fit on one row, and a wide bar costs more. Past that, the sprites drawn last lose pixels on that row, and a development build of a game that draws rectangles writes two lines in mGBA's log when a row is over, naming the row. A whole screen of small rectangles is not what this call is for.
A piece that is exactly a sprite's own size costs only its width, so a 200 by 16 bar is about 224 on every row it covers, where four stretched pieces would cost about 550. The expensive sizes are the stretched ones: anything thinner than 8, and an even size that is not 8, 16, 32 or 64. A 240 by 4 bar costs about 550 on each row its pieces cover (they cover more rows than the bar is thick), and a 240 by 12 bar is two rows of stretched pieces that cost about 1,100 on the rows where they overlap. Three full-width bars like those on the same rows are more than the console can draw, and the sprites drawn last lose the end of the row - which looks like a bar with a piece missing, and is not the fault of anything drawn beside it. A bar 8, 16 or 32 tall costs a quarter to a half as much, and words are cheap by comparison: every four letters of plain text are one sprite that costs 32, so a whole line of 28 letters is about 224 (see draw_text_3d for a curved line).
draw_rect_fill(x - 16, y - 23, 32, 6, COLOR_RED);A small red bar, 32 pixels wide and 6 tall, with its middle 20 pixels above this instance (its corner is half the width, 16, to the left of x, and half the height, 3, above the middle line) - a plain building block for a health bar or a debug marker floating over a character.


Every size is drawn exactly: a 6 wide rectangle is 6 wide and a 200 wide one is 200. The console stretches one sprite to at most twice its own size, so a rectangle is made of one or more sprites laid side by side: 1 for an 8 by 8 rectangle and for most small sizes (each way an odd number, or 2, 4, 8 or 16), 4 for a 6 by 6 or a 12 by 12, 4 for a 200 by 16 bar, 6 for the whole 240 by 160 screen. One rectangle is at most 12 sprites (about 380 wide by 500 tall at the most): a bigger one is drawn smaller than asked, and a development build says so in its log. It costs ONE affine matrix, shared by all its sprites (none for exactly 8 by 8), for as long as this call keeps being made, freed the instant it stops, out of the project’s 32. One shared palette bank for every rectangle and color. 0 or negative w/h reads as 1 pixel, never a crash. If every matrix is already in use elsewhere, this draws nothing for that call that frame rather than the wrong size, and tries again the next. The console can draw only about 25 stretched sprites on any one row of the screen: past that, the ones drawn last lose pixels on that row, so keep many wide rectangles off the same rows. A bar whose height is 8, 16, 32 or 64 is drawn by the console at its own size and costs about a fifth of any other height (a full-width bar 16 tall is 256 of the 1,210 a row has, a 12 tall one 1,100), so three full-width bars on the same rows fit at 16 tall and do not at 12 or 4: make wide bars one of those heights. A development build says in its log when a row is over.